<meta charset="UTF-8" />

<textarea id="input" cols="200" rows="48"></textarea>

<script>
    /** @type { HTMLInputElement } */
    const inputElement = document.querySelector("#input");

    inputElement.oninput = function() {
        try {
            let obj;
            inputElement.value = JSON.stringify(eval(`obj=${inputElement.value}`), undefined, 2);
        } catch (error) {
            console.error(error);
        }
    };

</script>